#include "machine_type.h"
#include "ui_machine_type.h"
#include "main.h"


machine_type::machine_type(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::machine_type)
{
    ui->setupUi(this);

    ui->door_type_comboBox->addItem(trUtf8("自动双门方炉"),1);
    ui->door_type_comboBox->addItem(trUtf8("自动单门方炉"),2);
    ui->door_type_comboBox->addItem(trUtf8("手动双门方炉"),3);
    ui->door_type_comboBox->addItem(trUtf8("手动单门方炉"),4);
    ui->door_type_comboBox->addItem(trUtf8("双门圆炉"),5);
    ui->door_type_comboBox->addItem(trUtf8("单门圆炉"),6);
    ui->machine_type_comboBox->addItem(trUtf8("下排式"),true);
    ui->machine_type_comboBox->addItem(trUtf8("真空炉"),false);
    ui->watering_type_comboBox->addItem(trUtf8("补水型"),true);
    ui->watering_type_comboBox->addItem(trUtf8("加水型"),false);
    ui->exhaust_type_comboBox->addItem(trUtf8("压力控制"),true);
    ui->exhaust_type_comboBox->addItem(trUtf8("时间控制"),false);
    ui->serialcheck_comboBox->addItem(trUtf8("校验和"),true);
    ui->serialcheck_comboBox->addItem(trUtf8("无校验"),false);
    ui->exhaust_valve_multiplex_comboBox->addItem(trUtf8("是"),true);
    ui->exhaust_valve_multiplex_comboBox->addItem(trUtf8("否"),false);
    ui->IO_drive_type_comboBox->addItem(trUtf8("串口驱动"),true);
    ui->IO_drive_type_comboBox->addItem(trUtf8("直接IO驱动"),false);
    ui->temperature_control_type_comboBox->addItem(trUtf8("压力控制"),true);
    ui->temperature_control_type_comboBox->addItem(trUtf8("温度控制"),false);
    ui->record_print_type_comboBox->addItem(trUtf8("实时打印"),true);
    ui->record_print_type_comboBox->addItem(trUtf8("完成后打印"),false);

    ui->IO_tracker_comboBox->addItem(trUtf8("开"),true);
    ui->IO_tracker_comboBox->addItem(trUtf8("关"),false);
    ui->door_near_switch_comboBox->addItem(trUtf8("开"),true);
    ui->door_near_switch_comboBox->addItem(trUtf8("关"),false);
}

machine_type::~machine_type()
{
    delete ui;

}

void machine_type::entrance()
{
     DisplayLastValue();
     //exec();
     showFullScreen();
}

void machine_type::DisplayLastValue()
{

    ui->door_type_comboBox->setCurrentIndex(whole_machine_parameter.machine_type_id-1);

   if( whole_machine_parameter.bottom_exhaust_machine)
       ui->machine_type_comboBox->setCurrentIndex(0);
   else ui->machine_type_comboBox->setCurrentIndex(1);

   if(whole_machine_parameter.is_water_supply_type)
       ui->watering_type_comboBox->setCurrentIndex(0);
   else ui->watering_type_comboBox->setCurrentIndex(1);

   if(whole_machine_parameter.cold_exhaust_control_type)
       ui->exhaust_type_comboBox->setCurrentIndex(0);
   else ui->exhaust_type_comboBox->setCurrentIndex(1);

   if(whole_machine_parameter.ad_checksum)
       ui->serialcheck_comboBox->setCurrentIndex(0);
   else ui->serialcheck_comboBox->setCurrentIndex(1);

   if(whole_machine_parameter.exhaust_valve_multiplex)
       ui->exhaust_valve_multiplex_comboBox->setCurrentIndex(0);
   else ui->exhaust_valve_multiplex_comboBox->setCurrentIndex(1);
   if(whole_machine_parameter.IO_drive_type)
       ui->IO_drive_type_comboBox->setCurrentIndex(0);
   else ui->IO_drive_type_comboBox->setCurrentIndex(1);

   if(whole_machine_parameter.temperature_control_type)
       ui->temperature_control_type_comboBox->setCurrentIndex(0);
   else ui->temperature_control_type_comboBox->setCurrentIndex(1);

    if(whole_machine_parameter.realtime_print_record)
        ui->record_print_type_comboBox->setCurrentIndex(0);
    else ui->record_print_type_comboBox->setCurrentIndex(1);

    if(whole_machine_parameter.IO_tracker)
        ui->IO_tracker_comboBox->setCurrentIndex(0);
    else ui->IO_tracker_comboBox->setCurrentIndex(1);

    if(whole_machine_parameter.door_near_switch)
        ui->door_near_switch_comboBox->setCurrentIndex(0);
    else ui->door_near_switch_comboBox->setCurrentIndex(1);
}
void machine_type::on_buttonBox_accepted()
{

     BUTTON_SOUND;
   whole_machine_parameter.machine_type_id=ui->door_type_comboBox->itemData(
               ui->door_type_comboBox->currentIndex()).toInt();

   whole_machine_parameter.bottom_exhaust_machine=ui->machine_type_comboBox->itemData(
                  ui->machine_type_comboBox->currentIndex()).toBool();

   whole_machine_parameter.is_water_supply_type=ui->watering_type_comboBox->itemData(
                  ui->watering_type_comboBox->currentIndex()).toBool();
   whole_machine_parameter.cold_exhaust_control_type=ui->exhaust_type_comboBox->itemData(
                  ui->exhaust_type_comboBox->currentIndex()).toBool();
   whole_machine_parameter.ad_checksum=ui->serialcheck_comboBox->itemData(
                  ui->serialcheck_comboBox->currentIndex()).toBool();
   whole_machine_parameter.exhaust_valve_multiplex=ui->exhaust_valve_multiplex_comboBox->itemData(
                  ui->exhaust_valve_multiplex_comboBox->currentIndex()).toBool();
   whole_machine_parameter.IO_drive_type=ui->IO_drive_type_comboBox->itemData(
                  ui->IO_drive_type_comboBox->currentIndex()).toBool();
   whole_machine_parameter.temperature_control_type=ui->temperature_control_type_comboBox->itemData(
                  ui->temperature_control_type_comboBox->currentIndex()).toBool();
   whole_machine_parameter.realtime_print_record=ui->record_print_type_comboBox->itemData(
                  ui->record_print_type_comboBox->currentIndex()).toBool();
   whole_machine_parameter.IO_tracker=ui->IO_tracker_comboBox->itemData(
                  ui->IO_tracker_comboBox->currentIndex()).toBool();
   whole_machine_parameter.door_near_switch=ui->door_near_switch_comboBox->itemData(
                  ui->door_near_switch_comboBox->currentIndex()).toBool();

   config_changed=true;
}

void machine_type::on_buttonBox_rejected()
{
  DisplayLastValue();
}

